export default {
    fetch(type, url, params) {
        return new Promise((resolve, reject) => {
            switch (type) {
                case 'post':
                    axios.post(url, params)
                        .then(response => {
                            resolve(response.data);
                        })
                        .catch((error) => {
                            reject(error);
                        })
                    break;
                case 'get':
                    axios.get(url, params)
                        .then(response => {
                            resolve(response.data);
                        })
                        .catch((error) => {
                            reject(error);

                        })
                    break;
            }

        })
    },
    fetch2(type, url, params,) {
        return new Promise((resolve, reject) => {
            switch (type) {
                case 'post':

                    axios.post(url, params,{responseType: 'arraybuffer'})
                        .then(response => {
                            let filename = response.headers['content-disposition']
                            filename = decodeURIComponent(filename)
                            resolve({data:response.data,filename:filename});
                        })
                        .catch((error) => {
                            reject(error);
                        })
                    break;
                case 'get':
                    axios.get(url, params)
                        .then(response => {
                            resolve(response.data);
                        })
                        .catch((error) => {
                            reject(error);

                        })
                    break;
            }

        })
    },
}
